package com.lucky.common.service;

import com.lucky.common.base.BaseService;
import com.lucky.common.cache.ParamCache;
import com.lucky.common.mapper.ParamMapper;
import com.lucky.common.pojo.po.ParamPO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class ParamService extends BaseService<ParamMapper,ParamPO> {

	public Logger log = LoggerFactory.getLogger(ParamService.class);
	
	@Resource
	ParamMapper paramMapper;

	@PostConstruct
	void init(){
		list().forEach(p -> ParamCache.put(p.getParaCode(), p.getParaValue()));
	}


	public String getValue(String key){
		return paramMapper.getValue(key);
	}

	public String getCacheValue(String key){
		String v = ParamCache.get(key);
		if(v == null){
			v = getValue(key);
			ParamCache.put(key, v);
		}
		return v;
	}
}
